|
|
 |
|
|
|
|
' If success, convert the byte array
' to a Unicode string.
If lngStatus = ERROR_SUCCESS Then vntValue = bytBuf
txtKeyValue = StrConv(vntValue, vbUnicode) Else
txtKeyValue = "Error Reading Value"
End If
Else
txtKeyValue = "Error Opening Key"
End If
' Close the Key lngStatus = RegCloseKey(lngKey)
End Sub |
|
|
|
|
|
|
|
|
To begin using these Windows API calls, you need to create a string variable with the full key of where you want to get to in the Registry. You open this key using the RegOpenKeyEx() function. This function returns a status flag that indicates whether the key was opened successfully. It also fills in the lngKey variable by reference with a handle to the key. |
|
|
|
|
|
|
|
|
Once the key is open, you can then retrieve a value from that key by using the key name in the RegQueryValueEx() function. Because all the data is stored in the Registry in ANSI character format, you need to pass in a Byte array and have the Registry functions fill it in. After the value is placed into the Byte array, you use the StrConv() function to convert the Byte array to a Visual Basic string. Finally, you must close the key using the RegCloseKey() function. |
|
|
|
|
|
|
|
|
Saving Data Using API Calls |
|
|
|
|
|
|
|
|
Youll now learn to save information to the Registry using the Windows API calls. Youll open a key in the same manner as you did for the Get routine. To save a value to a key, use the RegSetValueEX() function: |
|
|
|
 |
|
|
|
|
Private Sub cmdRegSet_Click()
Dim lngStatus As Long
Dim lngKey As Long
Dim strKey As String
Dim strValue As String |
|
|
|
|
|